package cn.doitedu.rtdw.udf;

import org.apache.flink.table.functions.ScalarFunction;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class ArrayDeSer extends ScalarFunction {

    public Double[] eval(byte[] byteArray) throws IOException {
        Double[] resultDoubles = new Double[byteArray.length / 8];

        byte[] tmp = new byte[8];
        for (int i = 0; i < resultDoubles.length; i++) {
            System.arraycopy(byteArray, i * 8, tmp, 0, 8);
            double v = Bytes.toDouble(tmp);
            resultDoubles[i] = v;
        }

        return resultDoubles;
    }
}
